package com.itpuyang.thread;

public class Foodie extends Thread{

    //消费者要一直执行：使用后循环
    //并发执行同步代码块


    @Override
    public void run() {
        while(true){
            synchronized (Desk.lock){
                if (Desk.count == 0){
                    break;
                }else{
                    if (!Desk.flag){
                        //有汉堡包
                        System.out.println("吃货在吃汉堡包");
                        Desk.flag = false;
                        Desk.lock.notifyAll();
                        Desk.count--;
                    }else{
                        //么有汉堡包，等待
                        try {
                            Desk.lock.wait();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }

                    }
                }

            }
        }


    }
}
